# Maintainer: Felix Yan <felixonmars@archlinux.org>

_hkgname=lucid
pkgname=haskell-lucid
pkgver=2.11.20230408
pkgrel=27
pkgdesc="Clear to write, read and edit DSL for HTML"
url="https://github.com/chrisdone/lucid"
license=('BSD')
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-blaze-builder' 'haskell-hashable' 'haskell-mmorph')
makedepends=('ghc' 'haskell-bifunctors' 'haskell-hspec' 'haskell-hunit')
source=(https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz)
sha512sums=('7503c5f74621498d31f71546946deb380038a044357b0b5a3529e53a8fc35e574b5843b497a248e019402ae5d444100732fa7f1df8220671bfab36f7612e1b0c')

build() {
    cd $_hkgname-$pkgver
    
    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $_hkgname-$pkgver
    # Test result depending on version of hashable
    runhaskell Setup test --show-details=direct || echo "Tests failed"
}

package() {
    cd $_hkgname-$pkgver
    
    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
